package com.taorenqi.business.fragment.login;


import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.taorenqi.business.R;
import com.taorenqi.business.activity.LoginActivity;
import com.taorenqi.business.fragment.base.BaseBackFragment;
import com.taorenqi.business.widget.statusview.StatusView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 找回密码成功
 * A simple {@link Fragment} subclass.
 */
public class ModifySuccessfullyFragment extends BaseBackFragment {


    @Bind(R.id.status_view)
    StatusView statusView;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.tv_changePw_time)
    TextView tvChangePwTime;
    @Bind(R.id.ll_changePw_login)
    LinearLayout llChangePwLogin;
    @Bind(R.id.activity_change_pw_suc)
    LinearLayout activityChangePwSuc;

    private int time = 3;


    public static ModifySuccessfullyFragment newInstance() {
        // Required empty public constructor
        ModifySuccessfullyFragment fragment = new ModifySuccessfullyFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_modify_successfully, container, false);
        ButterKnife.bind(this, view);
        initView();
        handler.postDelayed(runnable, 1000);
        return view;
    }

    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (time==1){
                Intent intent = new Intent();
                intent.setClass(_mActivity, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
            time--;
            if (tvChangePwTime != null) {
                tvChangePwTime.setText(time + "秒之后自动跳转到登录界面");
                handler.postDelayed(this, 1000);
            }
        }
    };
    private void initView() {
        toolbar.setTitle("找回密码成功");
        initToolbarNav(toolbar);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tv_changePw_time, R.id.ll_changePw_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_changePw_time:
                break;
            case R.id.ll_changePw_login:
                Intent intent = new Intent();
                intent.setClass(_mActivity, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
        }
    }
}
